package dome1.queuedemo;


public class MyQueue {
    static class ListNode{
        public int val;
        public ListNode prev;
        public ListNode next;
        public ListNode(int val){
            this.val = val;
        }
    }
    public ListNode head;
    public ListNode last;
    //插入尾部节点
    public void offer(int val){
        ListNode node = new ListNode(val);
        if(head == null){
            head = last = node;
        }else{
            last.next = node;
            node.prev = last;
            last = node;
        }
    }
    //删去头结点
    public int poll(){
        if(empty()){
            return -1;
        }
        if(head.next == null){
            head = null;
            last = null;
            return -1;
        }
        int val = head.val;
        head = head.next;
        head.prev = null;
        return val;
    }
    public boolean empty(){
        return head == null;
    }
    //查看队头
    public int peek(){
        if (empty()){
            return -1;
        }
        return head.val;
    }
}
